home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl67.lha / tcl6.7 / doc / SplitList.3 < prev    next >
Text File  |  1993-01-31  |  6KB  |  160 lines

  1. '\"
  2. '\" Copyright 1989-1991 Regents of the University of California
  3. '\" Permission to use, copy, modify, and distribute this
  4. '\" documentation for any purpose and without fee is hereby
  5. '\" granted, provided that this notice appears in all copies.
  6. '\" The University of California makes no representations about
  7. '\" the suitability of this material for any purpose.  It is
  8. '\" provided "as is" without express or implied warranty.
  9. '\" 
  10. '\" $Header: /user6/ouster/tcl/man/RCS/SplitList.3,v 1.9 93/01/31 15:35:40 ouster Exp $ SPRITE (Berkeley)
  11. '\" 
  12. .so man.macros
  13. .HS Tcl_SplitList tcl
  14. .BS
  15. .SH NAME
  16. Tcl_SplitList, Tcl_Merge, Tcl_ScanElement, Tcl_ConvertElement \- manipulate Tcl lists
  17. .SH SYNOPSIS
  18. .nf
  19. \fB#include <tcl.h>\fR
  20. .sp
  21. int
  22. \fBTcl_SplitList\fR(\fIinterp, list, argcPtr, argvPtr\fR)
  23. .sp
  24. char *
  25. \fBTcl_Merge\fR(\fIargc, argv\fR)
  26. .sp
  27. .VS
  28. int
  29. \fBTcl_ScanElement\fR(\fIsrc, flagsPtr\fR)
  30. .sp
  31. int
  32. \fBTcl_ConvertElement\fR(\fIsrc, dst, flags\fR)
  33. .VE
  34. .SH ARGUMENTS
  35. .AS Tcl_Interp ***argvPtr
  36. .AP Tcl_Interp *interp out
  37. Interpreter to use for error reporting.
  38. .AP char *list in
  39. Pointer to a string with proper list structure.
  40. .AP int *argcPtr out
  41. Filled in with number of elements in \fIlist\fR.
  42. .AP char ***argvPtr out
  43. \fI*argvPtr\fR will be filled in with the address of an array of
  44. pointers to the strings that are the extracted elements of \fIlist\fR.
  45. There will be \fI*argcPtr\fR valid entries in the array, followed by
  46. a NULL entry.
  47. .AP int argc in
  48. Number of elements in \fIargv\fR.
  49. .AP char **argv in
  50. Array of strings to merge together into a single list.
  51. Each string will become a separate element of the list.
  52. .AP char *src in
  53. .VS
  54. String that is to become an element of a list.
  55. .AP int *flagsPtr in
  56. Pointer to word to fill in with information about \fIsrc\fR.
  57. The value of *\fIflagsPtr\fR must be passed to \fBTcl_ConvertElement\fR.
  58. .AP char *dst in
  59. Place to copy converted list element.  Must contain enough characters
  60. to hold converted string.
  61. .AP int flags in
  62. Information about \fIsrc\fR. Must be value returned by previous
  63. call to \fBTcl_ScanElement\fR, possibly OR-ed
  64. with \fBTCL_DONT_USE_BRACES\fR.
  65. .VE
  66. .BE
  67.  
  68. .SH DESCRIPTION
  69. .PP
  70. These procedures may be used to disassemble and reassemble Tcl lists.
  71. \fBTcl_SplitList\fR breaks a list up into its constituent elements,
  72. returning an array of pointers to the elements using
  73. \fIargcPtr\fR and \fIargvPtr\fR.
  74. While extracting the arguments, \fBTcl_SplitList\fR obeys the usual
  75. rules for backslash substitutions and braces.  The area of
  76. memory pointed to by \fI*argvPtr\fR is dynamically allocated;  in
  77. addition to the array of pointers, it
  78. also holds copies of all the list elements.  It is the caller's
  79. responsibility to free up all of this storage by calling
  80. .DS
  81. \fBfree\fR((char *) \fI*argvPtr\fR)
  82. .DE
  83. when the list elements are no longer needed.
  84. .PP
  85. \fBTcl_SplitList\fR normally returns \fBTCL_OK\fR, which means the list was
  86. successfully parsed.
  87. If there was a syntax error in \fIlist\fR, then \fBTCL_ERROR\fR is returned
  88. and \fIinterp->result\fR will point to an error message describing the
  89. problem.
  90. If \fBTCL_ERROR\fR is returned then no memory is allocated and \fI*argvPtr\fR
  91. is not modified.
  92. .PP
  93. \fBTcl_Merge\fR is the inverse of \fBTcl_SplitList\fR:  it
  94. takes a collection of strings given by \fIargc\fR
  95. and \fIargv\fR and generates a result string
  96. that has proper list structure.
  97. This means that commands like \fBindex\fR may be used to
  98. extract the original elements again.
  99. In addition, if the result of \fBTcl_Merge\fR is passed to \fBTcl_Eval\fR,
  100. it will be parsed into \fIargc\fR words whose values will
  101. be the same as the \fIargv\fR strings passed to \fBTcl_Merge\fR.
  102. \fBTcl_Merge\fR will modify the list elements with braces and/or
  103. backslashes in order to produce proper Tcl list structure.
  104. The result string is dynamically allocated
  105. using \fBmalloc()\fR;  the caller must eventually release the space
  106. using \fBfree()\fR.
  107. .PP
  108. If the result of \fBTcl_Merge\fR is passed to \fBTcl_SplitList\fR,
  109. the elements returned by \fBTcl_SplitList\fR will be identical to
  110. those passed into \fBTcl_Merge\fR.
  111. However, the converse is not true:  if \fBTcl_SplitList\fR
  112. is passed a given string, and the resulting \fIargc\fR and
  113. \fIargv\fR are passed to \fBTcl_Merge\fR, the resulting string
  114. may not be the same as the original string passed to \fBTcl_SplitList\fR.
  115. This is because \fBTcl_Merge\fR may use backslashes and braces
  116. differently than the original string.
  117. .PP
  118. .VS
  119. \fBTcl_ScanElement\fR and \fBTcl_ConvertElement\fR are the
  120. procedures that do all of the real work of \fBTcl_Merge\fR.
  121. \fBTcl_ScanElement\fR scans its \fIsrc\fR argument
  122. and determines how to use backslashes and braces
  123. when converting it to a list element.
  124. It returns an overestimate of the number of characters
  125. required to represent \fIsrc\fR as a list element, and
  126. it stores information in \fI*flagsPtr\fR that is needed
  127. by \fBTcl_ConvertElement\fR.
  128. .PP
  129. \fBTcl_ConvertElement\fR is a companion procedure to \fBTcl_ScanElement\fR.
  130. It does the actual work of converting a string to a list element.
  131. Its \fIflags\fR argument must be the same as the value returned
  132. by \fBTcl_ScanElement\fR.
  133. \fBTcl_ConvertElement\fR writes a proper list element to memory
  134. starting at *\fIdst\fR and returns a count of the total number
  135. of characters written, which will be no more than the result
  136. returned by \fBTcl_ScanElement\fR.
  137. \fBTcl_ConvertElement\fR writes out only the actual list element
  138. without any leading or trailing spaces: it is up to the caller to
  139. include spaces between adjacent list elements.
  140. .PP
  141. \fBTcl_ConvertElement\fR uses one of two different approaches to
  142. handle the special characters in \fIsrc\fR.  Wherever possible, it
  143. handles special characters by surrounding the string with braces.
  144. This produces clean-looking output, but can't be used in some situations,
  145. such as when \fIsrc\fR contains unmatched braces.
  146. In these situations, \fBTcl_ConvertElement\fR handles special
  147. characters by generating backslash sequences for them.
  148. The caller may insist on the second approach by OR-ing the
  149. flag value returned by \fBTcl_ScanElement\fR with
  150. \fBTCL_DONT_USE_BRACES\fR.
  151. Although this will produce an uglier result, ireis useful in some
  152. special situations, such as when \fBTcl_ConvertElement\fR is being
  153. used to generate a portion of an argument for a Tcl command.
  154. In this case, surrounding \fIsrc\fR with curly braces would cause
  155. the command not to be parsed correctly.
  156. .VE
  157.  
  158. .SH KEYWORDS
  159. backslash, convert, element, list, merge, split, strings
  160.